package org.zoomdev.zoom.dao;

import org.zoomdev.zoom.dao.transaction.Transactions;

import java.util.function.Supplier;

public class Db {

    public static Boolean trans(Supplier<Boolean> supplier, int level) {
        Transactions transactions = Transactions.get();
        try {
            transactions.beginTrans(level);
            Boolean ret = supplier.get();
            transactions.commitTrans();
            return ret;
        } catch (Exception e) {
            transactions.rollbackTrans();
            throw new DaoException(e);
        }

    }
}
